import { ConfigService } from '@nestjs/config';
import { RedisModule } from '@nestjs-modules/ioredis';
import { Global, Module } from '@nestjs/common';
import { ConfigEnum } from '../enum/config.enum';
import { RedisCommonService } from './redis.service';

@Global()
@Module({
  imports: [
    RedisModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'single',
        url: configService.get(ConfigEnum.REDIS_URL),
        options: {
          password: configService.get(ConfigEnum.REDIS_PASSWD),
          db: 6,
        },
      }),
    }),

    // RedisModule.forRoot({
    //   type: 'single',
    //   url: 'redis://192.168.203.128:6379',
    //   options: {
    //     password: 'Lzx542684.@',
    //     db: 6,
    //   },
    // }),
  ],
  providers: [RedisCommonService],
  exports: [RedisCommonService],
})
export class RedisCacheModule {}
